import { createRouter, createWebHistory } from 'vue-router'

export const routerFiles = import.meta.glob('../views/**/index.vue')
const routeList = [
  {
    path: '/redirect',
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  }
]
const upperName = name => name.split('/').map(da => da.replace(/^\w/g, d => d.toUpperCase())).join('')
// const upperName = name => name


for (const [key, component] of Object.entries(routerFiles)) {
  const path = key.replace('../views', '').replace('/index.vue', '')
  const isEdit = path.indexOf('/edit') > -1
  // if (isEdit) {
  //   routeList.push({
  //     path: path,
  //     name: upperName(path.replace('/', '')),
  //     component,
  //     props: isEdit,
  //     hidden: isEdit,
  //     meta: {}
  //   })
  // }
  routeList.push({
    path: path,
    name: upperName(path.replace('/', '')),
    component,
    props: isEdit,
    hidden: isEdit,
    meta: {}
  })
}

export const routes = routeList

export const history = createWebHistory(import.meta.env.BASE_URL)

const router = createRouter({
  strict: true,
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})
export default router